package com.example.ribbonserver.rxjava;

import rx.Observable;
import rx.Subscriber;

/**
 * @author zhanghaidong
 * @version v1.0
 * @description
 * @date 2020/4/22
 */
public class RxJavaTest {
    public static void main(String[] args) {

        //创建事件源
        Observable<String> observable = Observable.unsafeCreate(new Observable.OnSubscribe<String>() {
            @Override
            public void call(Subscriber<? super String> subscriber) {
                subscriber.onNext("Hello RxJava");
                subscriber.onNext("I am 程序员DD");
                subscriber.onCompleted();
            }
        });

        //创建订阅者
        Subscriber<String> subscriber = new Subscriber<String>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(String o) {
                System.out.println("Subscriber: " + o);
            }
        };

        //订阅
        observable.subscribe(subscriber);
    }
}
